package controllor

import (
	"fitness/internal/service"
	"fitness/pkg/middleware"
	"github.com/gin-gonic/gin"
)

type RoleController struct {
	RoleService *service.RoleService
	Rbac        *middleware.Rbac
}

func NewRoleController(RoleService *service.RoleService, rbac *middleware.Rbac) *RoleController {
	return &RoleController{
		RoleService: RoleService,
		Rbac:        rbac,
	}
}

func (api *RoleController) InitApiRouter(engine *gin.Engine) {
	RoleV1 := engine.Group("/roles")
	{
		//角色
		RoleV1.GET("/options", middleware.Jwt, api.RoleService.GetRolesOptions)
		//获取分页 'LOGIN','USER','ROLE','DEPT','MENU','DICT','OTHER'
		RoleV1.GET("/page", middleware.Jwt, api.RoleService.GetPage)
		//查找
		RoleV1.GET("/:roleId/form", middleware.Jwt, api.RoleService.GetRoleForm)
		//权限分配
		RoleV1.GET("/menuIds/:roleId", middleware.Jwt, api.RoleService.GetRoleMenuIds)
		//分配菜单(包括按钮权限)给角色
		RoleV1.PUT("/menus/:roleId", middleware.Jwt, api.RoleService.AssignMenusToRole)
		//新增角色
		RoleV1.POST("", middleware.Jwt, api.Rbac.RbacAuth("sys:role:add"), api.RoleService.AddRole)
		//编辑
		RoleV1.PUT("/:id", middleware.Jwt, api.Rbac.RbacAuth("sys:role:edit"), api.RoleService.UpdateRole)
		//删除
		RoleV1.DELETE("/:ids", middleware.Jwt, api.Rbac.RbacAuth("sys:role:delete"), api.RoleService.DeleteRole)
	}
}
